package util;

import java.util.Properties;
import java.util.Random;

public class Proffession {

    private static Properties properties = new Properties();

    public static void main(String[] args) throws Exception {
        properties.loadFromXML(Proffession.class.getClassLoader()
                .getResourceAsStream("proffession.xml"));

        for (int i = 0; i < getIntProperties("count"); i++) {
            startClicker("click.exe " + getIntProperties("x.1") + " "
                    + +getIntProperties("y.1"));
            Thread.sleep(getRandomProperties("delay.1"));

            startClicker("click.exe " + getIntProperties("x.2") + " "
                    + +getIntProperties("y.2"));
            Thread.sleep(getRandomProperties("delay.2"));
        }
    }

    public static int getIntProperties(String name) throws Exception {
        return Integer.parseInt(properties.getProperty(name));
    }

    public static int getRandomProperties(String name) throws Exception {
        return Integer.parseInt(properties.getProperty(name))
                + new Random().nextInt(Integer.parseInt(properties
                        .getProperty(name + ".random")));
    }

    public static void startClicker(String command) throws Exception {
        Process process = Runtime.getRuntime().exec(command);
        process.waitFor();
    }
}
